package com.example.springbootsfzy.util;

import lombok.Data;

import java.util.HashMap;
import java.util.Map;

@Data
public class R {
    private int code;
    private String msg;
    private Object data;
    private Map<String, Object> additionalData = new HashMap<>();  // 用于存放额外的数据

    public static R ok(Object data) {




        R r = new R();
        r.setCode(200);
        r.setMsg("操作成功");
        r.setData(data);
        return r;
    }

    public static R fail(String msg) {
        R r = new R();
        r.setCode(500);
        r.setMsg(msg);
        return r;
    }

    public static R error(String msg) {
        R r = new R();
        r.setCode(500);
        r.setMsg(msg);
        return r;
    }

    // 向 R 中添加额外的数据
    public R put(String key, Object value) {
        this.additionalData.put(key, value);
        return this;
    }

    //token验证失败后就会返回600
    public static R error2(String msg) {
        R r = new R();
        r.setCode(600);
        r.setMsg(msg);
        return r;
    }
}
